package com.itheima.dao.impl;

import com.itheima.dao.StudentDao;
import com.itheima.domain.Student;

import java.util.ArrayList;

public class StudentDaoImpl implements StudentDao {
    ArrayList<Student> allStudents = new ArrayList<>();

    {
        allStudents.add(new Student("itheima000", "admin", "22", "1999-09-09"));
        allStudents.add(new Student("itheima001", "root", "22", "1999-09-09"));
    }

    @Override
    public void addStudent(Student student) {
        allStudents.add(student);
    }

    @Override
    public void delectStudent(int index) {
        allStudents.remove(index);
    }

    @Override
    public void updateStudent(int index, Student student) {
        allStudents.set(index,student);
    }

    @Override
    public ArrayList<Student> findAllStudent() {
        return allStudents;
    }

    @Override
    public int findStudentById(String id) {
        for (int i = 0; i < allStudents.size(); i++) {
            if (allStudents.get(i).getId().equals(id)){
                return i;
            }
        }
        return -1;
    }
}

